package com.atguigu.gmall.item.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.Thymeleaf;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ExecutorServiceConfig {

    @Bean
    public ExecutorService executorService(
            @Value("${threadpool.params.corePoolSize}") Integer corePoolSize,
            @Value("${threadpool.params.maximumPoolSize}") Integer maximumPoolSize,
            @Value("${threadpool.params.keepAliveTime}") Integer keepAliveTime,
            @Value("${threadpool.params.workQueueLength}") Integer workQueueLength
    ){
        /*
        int corePoolSize,
      int maximumPoolSize,
      long keepAliveTime,
      TimeUnit unit,
      BlockingQueue<Runnable> workQueue,
      ThreadFactory threadFactory,
      RejectedExecutionHandler handler
         */
        return new ThreadPoolExecutor(corePoolSize , maximumPoolSize , keepAliveTime ,
                TimeUnit.SECONDS , new ArrayBlockingQueue<>(workQueueLength));
    }

}
